package com.zw.pm.module.board.dailyoutput;

import com.zw.pm.base.BaseController;
import com.zw.pm.common.JsonResult;
import com.zw.pm.gen.entity.Factory;
import com.zw.pm.gen.entity.TaskDaily;
import com.zw.pm.module.project.build.ProjectModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 日产量 控制层
 * @Author: China.sgl
 * @Date: 2019/9/16 09:11
 */
@Controller
@RequestMapping("/board/daily")
public class DailyOutputController extends BaseController {

    @Autowired
    private DailyOutputService dailyOutputService;

    /**
     * 日产量 页面
     *
     * @return 页面路径
     */
    @GetMapping
    @RequiresPermissions({"board:daily"})
    public String daily(Model model) {
        model.addAttribute("factories", dailyOutputService.findFactories());
        return "board/daily/page";
    }

    /**
     * 项目列表
     *
     * @param projectModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"board:daily"})
    public JsonResult list(ProjectModel projectModel) {
        startPage();
        List<ProjectModel> list = dailyOutputService.findProjectDaily(projectModel);
        return jsonResult(list);
    }

    /**
     * 录入
     *
     * @param taskDaily taskDaily
     * @return json
     */
    @ResponseBody
    @PostMapping("/input")
    @RequiresPermissions({"board:daily"})
    public JsonResult input(TaskDaily taskDaily) {
        return jsonResult(dailyOutputService.saveTaskDaily(taskDaily));
    }

    /**
     * 查询任务下达工厂
     *
     * @param id 项目ID
     * @return list
     */
    @ResponseBody
    @PostMapping("/taskFactory")
    @RequiresPermissions({"board:daily"})
    public List<Factory> findTaskFactory(Integer id) {
        return dailyOutputService.findTaskFactory(id);
    }

    /**
     * 查询项目日报表
     *
     * @param dailyOutputModel dailyOutputModel
     * @return json
     */
    @ResponseBody
    @PostMapping("/projectDailyList")
    @RequiresPermissions({"board:daily"})
    public JsonResult list(DailyOutputModel dailyOutputModel) {
        startPage();
        List<DailyOutputModel> list = dailyOutputService.findProjectDailyList(dailyOutputModel);
        return jsonResult(list);
    }

    /**
     * 删除
     *
     * @param taskDaily taskDaily
     * @return json
     */
    @ResponseBody
    @PostMapping("/del")
    @RequiresPermissions({"board:daily"})
    public JsonResult del(TaskDaily taskDaily) {
        return jsonResult(dailyOutputService.delTaskDaily(taskDaily));
    }

    /**
     * 根据ID查询
     *
     * @param id id
     * @return TaskDaily
     */
    @ResponseBody
    @PostMapping("/id")
    @RequiresPermissions({"board:daily"})
    public DailyOutputModel id(Integer id) {
        return dailyOutputService.findTaskDaily(id);
    }

    /**
     * 修改日报
     *
     * @param taskDaily taskDaily
     * @return json 数据
     */
    @ResponseBody
    @PostMapping("/update")
    @RequiresPermissions({"board:daily"})
    public JsonResult update(TaskDaily taskDaily) {
        return jsonResult(dailyOutputService.updateTaskDaily(taskDaily));
    }


}
